<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.8.0">

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->

    

    
        <meta name="description" content="参考链接：

windeployqt生成依赖库：https://blog.csdn.net/windsnow1/article/details/78004265
NSIS生成安装包：https://blog.csdn.net/m1223853767/article/details/79702064
">
    

    <!--Author-->
    
        <meta name="author" content="Cyrus">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="QT程序windows环境打包发布">
    

    <!--Open Graph Description-->
    
        <meta property="og:description" content="参考链接：

windeployqt生成依赖库：https://blog.csdn.net/windsnow1/article/details/78004265
NSIS生成安装包：https://blog.csdn.net/m1223853767/article/details/79702064
">
    

    <!--Open Graph Site Name-->
        <meta property="og:site_name" content="Cyrus的技术空间">

    <!--Type page-->
    
        <meta property="og:type" content="article">
    

    <!--Page Cover-->
    
    
        <meta property="og:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

        <meta name="twitter:card" content="summary_large_image">

    

    
        <meta name="twitter:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

    <!-- Title -->
    
    <title>QT程序windows环境打包发布 - Cyrus的技术空间</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet">

    <!-- Google Analytics -->
    


    <!-- favicon -->
    

</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/blog/">Cyrus的技术空间</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/blog/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>QT程序windows环境打包发布</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                            Posted by Cyrus on
                        
                        
                            2019-10-10
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           
                <div class="col-lg-4 col-lg-offset-2 col-md-5 col-md-offset-1 post-tags">
                    
                        


<a href="/blog/tags/打包发布/">#打包发布</a>


                    
                </div>
                <div class="col-lg-4 col-md-5 post-categories">
                    
                        

<a href="/blog/categories/QT/">QT</a>

                    
                </div>
            

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>参考链接：</p>
<ul>
<li>windeployqt生成依赖库：<a href="https://blog.csdn.net/windsnow1/article/details/78004265" target="_blank" rel="noopener">https://blog.csdn.net/windsnow1/article/details/78004265</a></li>
<li>NSIS生成安装包：<a href="https://blog.csdn.net/m1223853767/article/details/79702064" target="_blank" rel="noopener">https://blog.csdn.net/m1223853767/article/details/79702064</a></li>
</ul>
<h3 id="一、依赖库生成"><a href="#一、依赖库生成" class="headerlink" title="一、依赖库生成"></a>一、依赖库生成</h3><ul>
<li>1、选择release环境，编辑，会生成release文件夹和.exe文件</li>
<li>2、如果有第三方动态库，将动态库拷贝到编译生成的release，运行程序(这一步可以省略)<br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_1.png" alt=""></li>
<li>3、将.exe文件拷贝出来，找到QT用的编辑器（这里是QT 5.12.5(MinGw7.3.0 64bit)),执行下面的代码：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd xxxxx\xxx\	//进入.exe所在的文件夹</span><br><span class="line">windeployqt xxx.exe</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_2.png" alt=""><br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_3.png" alt=""></p>
<ul>
<li>4、将第三方运态库文件拷到.exe同级目录。完成！</li>
</ul>
<p>这里说一下容易遇到的问题：</p>
<ul>
<li><p>1、在release环境编译后，到release文件夹运行程序，提示缺少.dll文件<br>百度及部分视频讲到qt安装目录下拷贝对应的.dll文件。这种方法在安装qt的电脑上可以运行，但是在没安装qt的电脑上还是会提示缺少其他底层的.dll文件。一个一个添加效率太低。<br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/error_1.png" alt="编译后提示缺少库"><br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/error_2.png" alt="在未安装qt的电脑上提示缺少底层库"></p>
</li>
<li><p>2、出现0xc000007b——应用程序无法正常启动<br>这个问题主要是编译器选的不对，例如我们要生成MinGW64位的程序，在QT中却使用了clang x86的编译器。查看下面两个位置设置是否对应：<br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_4.png" alt=""><br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_2.png" alt=""></p>
</li>
</ul>
<h3 id="二、NSIS生成安装包"><a href="#二、NSIS生成安装包" class="headerlink" title="二、NSIS生成安装包"></a>二、NSIS生成安装包</h3><p>使用NSIS生成安装包，我们主要会用到两个软件：</p>
<ul>
<li>1、NSIS，NSIS是一个基于脚本的打包软件，提供了安装、卸载、系统设置、文件解压缩等功能。但是脚本编写麻烦，所以又有了第二个软件NSIS Edit.</li>
<li>2、NSIS Edit，顾名思义，就是NSIS编辑器，可以通过可视化界面的方式配置脚本并编译生成安装包。</li>
</ul>
<p>具体的使用过程 <a href="https://blog.csdn.net/m1223853767/article/details/79702064" target="_blank" rel="noopener">NSIS制作软件安装包</a> 这篇文篇已经讲得非常详细,这里就不再重复，主要讲几个需要注意的地方。</p>
<ul>
<li>1、NSIS Edit 新建时，选择“文件”菜单中的 “新建脚本：向导“；</li>
<li>2、步骤4，授权文件，如果没有就删掉，不然编译会出错；</li>
<li>3、步骤5，先删除默认的两个示例文件。如果包含子文件夹，使用AddTreeDir添加。使用添加文件的话，文件夹不会添加，生成的安装包会缺少库。<br><img src="http://cyrus_huang.gitee.io/blog/2019/10/10/QT程序windows环境打包发布/winqt_5.png" alt=""></li>
</ul>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2020 Cyrus<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
                <p class="copyright text-muted"><a href="http://www.beian.miit.gov.cn">粤ICP备18110122号-1</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>